package com.zonski.jbots.game.resources;

import com.zonski.jbots.engine.*;

import com.zonski.jbots.game.JBotsConstants;
import com.zonski.jbots.game.EntityHelper;

import java.util.Vector;

/**
 * Resource that generates bombs
 */
public class BombMaker extends IntermittentResource
{
    private static final int DEFAULT_UPDATES_BETWEEN_BOMBS = 5;
    private static final int DEFAULT_COST = 1;

    public BombMaker()
    {
        super(DEFAULT_UPDATES_BETWEEN_BOMBS);
    }

    public int getCurrentChargeCost()
    {
        return DEFAULT_COST;
    }

    protected Entity create(Engine engine)
        throws Exception
    {
        boolean occupied = EntityHelper.isOccupied(this.getOwner(), engine);
        Entity bomb;
        if(!occupied)
        {
            EntityFactory entityFactory = engine.getEntityFactory();
            bomb = entityFactory.createEntity(JBotsConstants.BOMB);
            //bomb.bounds.setCentre(this.getOwner().bounds);
            EntityHelper.centreAtClosestTile(bomb.bounds,
                    this.getOwner().bounds, engine.getRoom());
            bomb.layerId = this.getOwner().layerId;
        }else{
            bomb = null;
        }
        return bomb;
    }

    public Resource copy()
    {
        BombMaker bombMaker = new BombMaker();
        bombMaker.setKillOwner(this.getKillOwner());
        bombMaker.setUpdatesBetweenCreations(getUpdatesBetweenCreations());
        return bombMaker;
    }
}
